home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 6.9 KB | 257 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWDbgStr.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFound.hpp"
-
- #include <stddef.h>
-
- // Need to include first so that FW_DEBUG is properly defined
- #ifndef FWDBGSTR_H
- #include "FWDbgStr.h"
- #endif
-
- #ifdef FW_DEBUG
-
- #ifndef SLPRIDEB_H
- #include "SLPriDeb.h"
- #endif
-
- #ifndef FWPRIMEM_H
- #include "FWPriMem.h"
- #endif
-
- #ifndef FWPRISTR_H
- #include "FWPriStr.h"
- #endif
-
- #ifndef FWPRIDEB_H
- #include "FWPriDeb.h"
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__FILES__)
- #include <Files.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__ERRORS__)
- #include <Errors.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__TEXTUTILS__)
- #include <TextUtils.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__SCRIPT__)
- #include <Script.h>
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment FWDebug
- #endif
-
- //========================================================================================
- // CLASS FW_CDebugStream
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CDebugStream::EndLine
- //----------------------------------------------------------------------------------------
-
- FW_CDebugStream& EndLine(FW_CDebugStream &stream)
- {
- #ifdef FW_BUILD_MAC
- char cr = 0x0D;
- return stream.Write((void*)&cr, sizeof(char));
- #endif
- #ifdef FW_BUILD_WIN
- char cr[2] = {0x0D, 0x0A}
- return stream.Write((void*)cr, sizeof(char) * 2);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDebugStream::FW_CDebugStream
- //----------------------------------------------------------------------------------------
-
- FW_CDebugStream::FW_CDebugStream()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDebugStream::~FW_CDebugStream
- //----------------------------------------------------------------------------------------
-
- FW_CDebugStream::~FW_CDebugStream()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDebugStream::WriteChunk
- //----------------------------------------------------------------------------------------
-
- FW_CDebugStream &FW_CDebugStream::WriteChunk(const void* data, size_t size)
- {
- return Write(data, size);
- // return Write((void*) " ", sizeof(char));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDebugStream::WriteBase10Number(long n)
- //----------------------------------------------------------------------------------------
-
- FW_CDebugStream & FW_CDebugStream::WriteBase10Number(unsigned long n)
- {
- char buf[20];
- char *s = &buf[20];
-
- *--s = 0;
- do
- {
- *--s = (char) (n % 10) + '0';
- n /= 10;
- } while (n != 0);
-
- return WriteChunk((void*) s, FW_PrimitiveStringLength(s));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDebugStream::WriteBase16Number(long n)
- //----------------------------------------------------------------------------------------
-
- FW_CDebugStream & FW_CDebugStream::WriteBase16Number(unsigned long n)
- {
- const char *digits = "0123456789ABCDEF";
- char buf[11] = "0x00000000";
- char *s = &buf[10];
-
- for (; n != 0; n /= 16)
- *--s = digits[(short) (n % 16)];
-
- return WriteChunk((void*) buf, 10);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDebugStream::operator<<(const signed char *string)
- //----------------------------------------------------------------------------------------
-
- FW_CDebugStream & FW_CDebugStream::operator<<(const signed char *string)
- {
- return WriteChunk((void*) string, FW_PrimitiveStringLength((const char *) string));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDebugStream::operator<<(signed char c)
- //----------------------------------------------------------------------------------------
-
- FW_CDebugStream & FW_CDebugStream::operator<<(signed char c)
- {
- return WriteChunk((void*) &c, sizeof(char));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDebugStream::operator<<(long n)
- //----------------------------------------------------------------------------------------
-
- FW_CDebugStream & FW_CDebugStream::operator<<(long n)
- {
- if (n < 0)
- {
- Write((void*) "-", sizeof(char));
- n = -n;
- }
- return WriteBase10Number(n);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDebugStream::operator<<(unsigned long n)
- //----------------------------------------------------------------------------------------
-
- FW_CDebugStream & FW_CDebugStream::operator<<(unsigned long n)
- {
- return WriteBase10Number(n);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDebugStream::operator<<(void* p)
- //----------------------------------------------------------------------------------------
-
- FW_CDebugStream & FW_CDebugStream::operator<<(void* p)
- {
- return WriteBase16Number((long) p);
- }
-
-
- //========================================================================================
- // CLASS FW_CMacDebugStr
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CMacDebugStr::FW_CMacDebugStr
- //----------------------------------------------------------------------------------------
- #ifdef FW_BUILD_MAC
- FW_CMacDebugStr::FW_CMacDebugStr()
- {
- fStr255[0] = 0;
- }
- #endif
-
- //----------------------------------------------------------------------------------------
- // FW_CMacDebugStr::~FW_CMacDebugStr
- //----------------------------------------------------------------------------------------
- #ifdef FW_BUILD_MAC
- FW_CMacDebugStr::~FW_CMacDebugStr()
- {
- Flush();
- }
- #endif
-
- //----------------------------------------------------------------------------------------
- // FW_CMacDebugStr::Write
- //----------------------------------------------------------------------------------------
- #ifdef FW_BUILD_MAC
- FW_CDebugStream &FW_CMacDebugStr::Write(const void* data, size_t size)
- {
- const char *p = (const char *)data;
-
- while (size-- != 0)
- {
- char ch = *p++;
-
- switch (ch)
- {
- case 0x0D:
- case '\0':
- Flush();
- break;
-
- default:
- if (fStr255[0] == 255)
- Flush();
- fStr255[++fStr255[0]] = ch;
- break;
- }
- }
-
- return *this;
- }
- #endif
-
- //----------------------------------------------------------------------------------------
- // FW_CMacDebugStr::Flush
- //----------------------------------------------------------------------------------------
- #ifdef FW_BUILD_MAC
- void FW_CMacDebugStr::Flush()
- {
- if (fStr255[0] != 0)
- ::DebugStr(fStr255);
- fStr255[0] = 0;
- }
- #endif
-
- #endif // FW_DEBUG
-